<template>
  <el-dialog
    v-model="visible"
    title="请假"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form
      :model="dataForm"
      :rules="rules"
      ref="dataFormRef"
      @keyup.enter="dataFormSubmitHandle()"
      label-width="120px"
    >
      <el-form-item prop="courseName" label="课程名称">
        <el-input v-model="dataForm.courseName" placeholder="课程名称" disabled="true"></el-input>
      </el-form-item>
      <el-form-item prop="teacherId" label="授课老师">
        <el-select v-model="dataForm.teacherId" disabled="true">
          <el-option
            v-for="item in teacherList"
            :key="item.id"
            :label="item.realName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="cause" label="批复内容">
        <el-input v-model="dataForm.cause" placeholder="批复内容" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
import { reactive, ref, defineProps } from "vue";
import baseService from "@/service/baseService";
import { isEmail, isMobile } from "@/utils/utils";
import { IObject } from "@/types/interface";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const roleList = ref<any[]>([]);
const dataFormRef = ref();

const dataForm = reactive({
  courseName: "",
  teacherId: "",
  classRoom: "",
  classTime: "",
  maxSize: "",
  description: ""
});
const props = defineProps({
  teacherList: Array
});
const rules = ref({
  name: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
  cause: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
});

const init = (value?: object) => {
  visible.value = true;
  dataForm.courseName = value.courseName;
  dataForm.id = value.id;
  dataForm.teacherId = value.teacherId;
  dataForm.cause = value.cause;
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    baseService
      .post("/cam/course/update", {
        ...dataForm
      })
      .then((res) =>
        ElMessage.success({
          message: "成功",
          duration: 500,
          onClose: () => {
            visible.value = false;
            emit("refreshDataList");
          }
        })
      );
  });
};

defineExpose({
  init
});
</script>

<style lang="less" scoped>
.mod-sys__user {
  .role-list {
    .el-select {
      width: 100%;
    }
  }
}
</style>
